<?php

/**
 * API Controller to get
 * array of tags that specific user (uid param) is
 * most actively posting questions or answers
 * 
 * @todo may implement the limit of no
 * more than 1000 results. It's unlikely
 * for user to have more anyway.
 *
 */

namespace StudyBuddy\Api\v1;

use StudyBuddy\Api\Api;

class Usertags extends Api {

    protected $aRequired = array('uid');

    /**
     * Array of data found
     * in USER_TAGS for one user
     * 
     * @var array
     */
    protected $aData = array();

    protected function main() {
        $this->getData()
                ->setOutput();
    }

    /**
     * Get User Tags data for user identified by uid 
     * request param and set result as
     * $this->aData
     * 
     * @throws \StudyBuddy\HttpResponseCodeException if no record
     * exists for this user
     * 
     * @return object $this
     */
    protected function getData() {
        $uid = $this->oRequest->get('uid', 'i', 0);
        $this->aData = $this->oRegistry->Mongo->USER_TAGS->findOne(
                array('_id' => $uid)
        );

        if (empty($this->aData)) {
            throw new \StudyBuddy\HttpResponseCodeException('No User tags found for userid ' . $uid, 404);
        }

        return $this;
    }

    /**
     *
     * Set to $this->oOutput object with
     * data from $this->aData
     *
     * @return object $this
     */
    protected function setOutput() {
        $this->oOutput->setData($this->aData);

        return $this;
    }

}
